package com.csw.shoppingPlatform.controller;

import java.awt.image.BufferedImage;
import java.io.OutputStream;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.csw.shoppingPlatform.util.SecurityCode;
import com.csw.shoppingPlatform.util.SecurityImage;

@Controller
@RequestMapping("captcha")
public class CaptchaAction {
	@RequestMapping("captcha")
	public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String securityCode = SecurityCode.getSecurityCode();
		HttpSession session = request.getSession();
		session.setAttribute("securityCode", securityCode);
		BufferedImage image = SecurityImage.createImage(securityCode);
		OutputStream out = response.getOutputStream();
		ImageIO.write(image, "png", out);
		return null;
	}
}